<?php 


   $fbconfig['appid' ] = "381660261944327";
   $fbconfig['secret'] = "928f255110037ed678004f34abf78964";

   $fbconfig['baseUrl']    =  HTML_BASE; 
   $fbconfig['appBaseUrl'] =  "http://apps.facebook.com/146779032148660/";
	
    if (isset($_GET['code'])){
        header("Location: " . $fbconfig['appBaseUrl']);
        exit;
    }
   
   
    if (isset($_GET['request_ids'])){
        //user comes from invitation
        //track them if you need
    }
    
   
    require "../src/facebook.php";
    
    


$facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true
    ));

    //Facebook Authentication part
    $user = $facebook->getUser();
    

 $loginUrl = $facebook->getLoginUrl();

if ($user) {
	
	/*$like_page = $facebook->api( array(
                         'method' => 'pages.isFan',
                         'page_id' => '570326972985204',
						 'uid' => $user,
                     ));*/
	  
	
  try {
	 $logoutUrl = $facebook->getLogoutUrl();
	 
    $user = $facebook->getUser();
    $user_profile = $facebook->api('/me');
  	
			
			
	
	/*$sql = "SELECT * FROM users WHERE fb_id = '$user'";
	$result = query($sql);
			
			if ($row = mysql_fetch_object($result)) {
				
				$_SESSION['Phone'] = $row->phone;
				$_SESSION['City'] = $row->city;
				$_SESSION['Kindergarten'] = $row->kindergarten;
				$_SESSION['ACCESS_SID'] = $row->access;
				
			} else {
				$sql = "INSERT INTO users (fb_id,full_name,email,access)
					   VALUES
						 ('$user','".escape($user_profile['name'])."','".$user_profile['email']."','1')
					   
					";
				query($sql);
				
				
			}
			
			$_SESSION['isLoggedIn'] = true;*/
			echo  $user;
			echo $user_profile['name'];
	
				
	  
  } catch (FacebookApiException $e) {
	  
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    //$user = null;
  
  }
  
  echo  $loginUrl;
  
}


?>